// ==UserScript==
// @name         复制网页标题和链接
// @namespace    https://bbs.tampermonkey.net.cn/
// @version      0.2.2
// @description  CTRL+X 复制网页标题和链接，方便分享!（有复制失败的随时反馈，感谢！）
// @author       张仨
// @match        *://*/*
// @grant        unsafeWindow
// @grant        GM_addStyle
// @grant        GM_setClipboard
// @noframes
// ==/UserScript==

let msg = document.createElement('div')
document.body.appendChild(msg)
msg.className = 'mymsg'
unsafeWindow.onkeydown = function (e) {
    let title = document.title;
    let url = location.href;
    if (e.ctrlKey && e.key == 'x') {
        msg.style.display = 'block'
        if (title && url) {
            GM_setClipboard('『' + title + '』' + url)
            msg.innerHTML = '😁复制成功'
        } else {
            msg.innerHTML = '😓复制失败'
        }
        setTimeout(() => {
            msg.style.display = 'none'
        }, 4800)
    }
}

GM_addStyle(`
    .mymsg {
        position: fixed;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        background: rgba(45, 45, 45, 0.8);
        width: 120px;
        height: 60px;
        z-index: 999999999;
        text-align: center;
        line-height: 60px;
        border-radius: 5%;
        font-size: 18px;
        font-family: 'STCaiyun';
        color: #fff;
        animation: mymsg 5s;
        display: none;
    }

    @keyframes mymsg {
        0% {
            opacity: 0;
        }

        50% {
            opacity: 1;
        }

        75% {
            opacity: 1;
        }

        100% {
            opacity: 0;
        }
    }
`)